/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;
import java.util.HashSet;
import java.util.TreeSet;

/**
 *
 * @author sio
 */
public class DAO {
    
    public static Collection <Dep> getLesDeps(){
       
        
         Collection <Dep> Deps = new TreeSet <Dep>();
         
        try{
           
            Connection con = Connect.get();
            Statement req = con.createStatement();
            Statement req2 = con.createStatement();
            ResultSet rs = req.executeQuery("select distinct departement from medecin;");
            
            while (rs.next()){
                
                Deps.add(new Dep(rs.getString("departement")));
                
            }
        }
        catch(SQLException e){
            System.out.println("Erreur SQL :" + e);
        }
        return Deps;
        
    }
    
    public static Collection <Med> getLesMeds(){
        Collection <Med> colMed = new TreeSet <Med>();
        try{
            Connection con = Connect.get();
            Statement req = con.createStatement();
             ResultSet rs = req.executeQuery("select * from medecin;");
             
             while(rs.next()){
                 colMed.add(new Med(rs.getString("nom"),rs.getString("prenom"),rs.getString("adresse"),rs.getString("tel"),rs.getString("specialitecomplementaire"),rs.getString("id"), rs.getString("departement")));
             }
        }catch (SQLException e){
            System.out.println("Erreur SQL :" + e);
              
          }
        return colMed;
    }
    
    public static Collection <Specialite> getLesSpec(){
        
        Collection <Specialite> colSpe = new TreeSet <Specialite>();
            
          try{
           
            Connection con = Connect.get();
            Statement req = con.createStatement();
            Statement req2 = con.createStatement();
            ResultSet rs = req.executeQuery("select distinct specialitecomplementaire from medecin;");
            
            while(rs.next()){
               if(rs.getString("specialitecomplementaire") != null){
                   colSpe.add(new Specialite(rs.getString("specialitecomplementaire")));
               }
            }
          }
          catch(SQLException e){
            System.out.println("Erreur SQL :" + e);
              
          }
        return colSpe;
    }
}
